package maze

import (
	"syscall/js"
)

var (
	currentMaze MazeCoverage
)

func init() {
	global.Set("maze_generate", js.FuncOf(maze_generate))
	global.Set("create_maze", js.FuncOf(create_maze))
	global.Set("maze_run_normal", js.FuncOf(maze_run_normal))
	global.Set("maze_run_breadth", js.FuncOf(maze_run_breadth))
	global.Set("maze_clean", js.FuncOf(maze_clean))
}

func maze_generate(this js.Value, i []js.Value) interface{} {
	if len(i) != 2 {
		return js.Undefined()
	}
	g := Generate(i[0].Int(), i[1].Int())
	vecJs := make([]interface{}, len(g))
	for i := range g {
		l := make([]interface{}, len(g[i]))
		for j := range g[i] {
			l[j] = g[i][j]
		}
		vecJs[i] = l
	}
	return js.ValueOf(vecJs)
}
